﻿@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_PageLayout.cshtml";
}
@section HeadSection
{
<script type="text/javascript">
        var url = "";
        $(function () {
            $(function () {
                bindReUserCombobox("selReUser");
            });

            $('#BatchRechargeList').datagrid({
                title: '批量充值管理',
                iconCls: 'icon-edit',
                url: '/Batch/BatchList',
                striped: true,
                idField: 'Id',
                border: true,
                loadMsg: '数据加载中...',
                singleSelect: true,
                pagination: true,
                pageSize: 20,
                pageList: [15, 20, 25, 30],
                frozenColumns: [[{ field: 'ck', checkbox: true }]],
                columns: [
                    [
                        { field: 'Id', title: 'Id', width: 60 },
                        { field: 'BatchName', title: '批次名称', width: 120, align: 'center' },
                        {
                            field: 'ProjectName',
                            title: '所属项目',
                            width: 150,
                            align: 'center'
                        },
                        { field: 'UploadUser', title: '上传用户', width: 120, align: 'center' },
                        { field: 'Total', title: '总笔数', width: 60, align: 'center' },
                        { field: 'Amount', title: '总金额(元)', width: 80, align: 'center' },
                        {
                            field: 'CheckStatus',
                            title: '审核状态',
                            width: 90,
                            align: 'center',
                            formatter: function (val, rec) {//0待审核，1已审核，-1拒绝
                                if (val == "0") {
                                    return "<span style='color:orangered;'>待审核</span>";
                                } else if (val == "1") {
                                    return "<span style='color:green;'>成功</span>";
                                } else {
                                    return "<span style='color:red;'>未通过</span>";
                                }
                            }
                        },
                        { field: 'CheckUser', title: '审核用户', width: 100, align: 'center' },
                        {
                            field: 'BatchStatus', //0待充值，1正在充值中，2部分成功，3全部成功
                            title: '批次充值情况',
                            width: 90,
                            align: 'center',
                            formatter: function (val, rec) {
                                if (val == "0") {
                                    return "<span style='color:orangered;'>待充值</span>";
                                } else if (val == "1") {
                                    return "<span style='color:green;'>充值中</span>";
                                } else if (val == "2") {
                                    return "<span style='color:red;'>部分成功</span>";
                                }
                                else if (val == "3") {
                                    return "<span style='color:blue;'>全部成功</span>";
                                }
                            }
                        },
                        {
                            field: 'ProcessTime',
                            title: '处理时间',
                            width: 130,
                            align: 'center',
                            formatter: function (val, rec) {
                                return JSONDateToJSDate(val);
                            }
                        },
                        {
                            field: 'AddTime',
                            title: '导入时间',
                            width: 130,
                            align: 'center',
                            formatter: function (val, rec) {
                                if (val) {
                                    return JSONDateToJSDate(val);
                                } else {
                                    return "";
                                }
                            }
                        },
                        {
                            field: 'opt',
                            title: '操作',
                            align: 'center',
                            width: 210,
                            hidden: @(Session["role"].ToString() == "0"?"false":"true"),
                            formatter: function (val, rec) {
                                var str = "";
                                if (rec.CheckStatus == 0 || rec.CheckStatus == -1) {
                                    str = '<a href="javascript:void(0);" onclick="if(confirm(\'确认审核通过吗？通过后系统将进行批量充值！\')) { check(' + rec.Id + ',1);}" style="color:green;">审核通过</a>';
                                    if (rec.CheckStatus == 0) {
                                        str += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="if(confirm(\'确认审核不通过吗？\')) { check(' + rec.Id + ',1);}" style="color:orangered;">审核不通过</a>';;
                                    }
                                }
                                //批次状态
                                if ((rec.BatchStatus == 0 || rec.BatchStatus == 2) && rec.CheckStatus == 1) { //未充值的，将开始批量充值
                                    str += '&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" onclick="if(confirm(\'确认开始批量充值吗？\')) { recharge(' + rec.Id + ');}" style="color:blue;">批量充值</a>';
                                }
                                return str;
                            }
                        }

                    ]
                ],
                toolbar: []
            });

            //尺寸
            $('#BatchRechargeList').datagrid('resize');

            //加载搜索框//在这个样式下。加载搜索框的div
            $(".datagrid-toolbar").append($("#divsearch"));
        });

        //搜索
        function doSearch() {
            $('#BatchRechargeList').datagrid('load', { userId: $("#selReUser").combobox("getValue"), batchName: $("#batchName").val(), batchStatus: $("#selBatchStatus").combobox("getValue"), beginTime: $("#beginTime").datetimebox("getValue"), endTime: $("#endTime").datetimebox("getValue") });
        }

        //审核 status:0待审核，1已审核，-1拒绝
        function check(batchId, status) {
            $.post("BatchCheck", { id: batchId, checkStatus: status }, function (data) {
                alert(data.msg);
                if (data.ret) {
                    $('#BatchRechargeList').datagrid('reload');
                }

            }, "json");
        }

        //开始批量充值
        function recharge(batchId) {
            $.post("BatchRech", { batchId: batchId }, function (data) {
                alert(data.msg);
                if (data.ret) {
                    $('#BatchRechargeList').datagrid('reload');
                }
            }, "json");
        }

        function Export() {
            var userId = $("#selReUser").combobox("getValue");
            var batchName = $("#batchName").val();
            var batchStatus = $("#selBatchStatus").combobox("getValue");
            var beginTime = $("#beginTime").datetimebox("getValue");
            var endTime = $("#endTime").datetimebox("getValue");

            var form = $("<form>");
            form.attr('style', 'display:none');
            form.attr('target', '');
            form.attr('method', 'post');
            form.attr('action', 'Export');

            var input1 = $('<input>');
            input1.attr('type', 'hidden');
            input1.attr('name', 'batchStatus');
            input1.attr('value', batchStatus);

            var input2 = $('<input>');
            input2.attr('type', 'hidden');
            input2.attr('name', 'userId');
            input2.attr('value', userId);

            var input3 = $('<input>');
            input3.attr('type', 'hidden');
            input3.attr('name', 'batchName');
            input3.attr('value', batchName);


            var inputBeginTime = $('<input>');
            inputBeginTime.attr('type', 'hidden');
            inputBeginTime.attr('name', 'beginTime');
            inputBeginTime.attr('value', beginTime);

            var inputEndTime = $('<input>');
            inputEndTime.attr('type', 'hidden');
            inputEndTime.attr('name', 'endTime');
            inputEndTime.attr('value', endTime);

            $('body').append(form);
            form.append(input1);
            form.append(input2);
            form.append(input3);
            form.append(inputBeginTime);
            form.append(inputEndTime);
            form.submit();
            form.remove();
        }
</script>
}
    <div id="divsearch" style="padding:5px;height:auto;">
        充值项目：<select id="selReUser" class="easyui-combobox" style="width: 180px">
            <option value="">请选择</option>
        </select>&nbsp;&nbsp;&nbsp;&nbsp;
        充值情况：<select id="selBatchStatus" class="easyui-combobox">
            <option value="-1">所有</option>
            <option value="0">待充值</option>
            <option value="1">充值中</option>
            <option value="2">部分成功</option>
            <option value="3">全部成功</option>
        </select>
        &nbsp;&nbsp;&nbsp;&nbsp;批次名称：<input type="text" name="batchName" id="batchName" style="width: 150px" />&nbsp;&nbsp;&nbsp;&nbsp;
        上传时间：
        <input class="easyui-datetimebox" id="beginTime" style="width:150px" /> - <input class="easyui-datetimebox" id="endTime" style="width: 150px" />
        <a href="#" class="easyui-linkbutton" onclick="doSearch();" iconcls="icon-search">搜索</a>
        <a href="#" class="easyui-linkbutton" onclick="Export();" iconcls="icon-redo">导出</a>
    </div>
<table id="BatchRechargeList" toolbar="#divsearch"></table>
